<div class="form wide">

    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'category-form',
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
        'afterValidate'=>"js:function(form,data,hasError){
            $('ul.ui-tabs-nav li a').removeClass('error');
            if (hasError)
            {
                $('#category-form div.row.error').each(function(index, value){
                    var tab_id = $(this).parents('div.ui-tabs-panel').attr('id');
                    $('ul.ui-tabs-nav li a[title=#'+tab_id+']').addClass('error');    
                });
                return false;    
            }
            else return true;
        }"
    ),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php //echo $form->errorSummary($model); ?>
    <?php $this->beginClip('info');?>
    <?php if (!$model->IsNewRecord) echo $form->hiddenField($model, "id"); ?>
    <?php $form->hiddenField($model, "ordering"); ?>
    <?php //$form->hiddenField($model, "parent_id"); ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'parent_id'); ?>
        <?php $this->widget('CategoryDropDownList', array(
        'model' => $model,
        'attribute' => 'parent_id',
        'htmlOptions' => array(
            'prompt' => 'Root',
        ),
        'exclude' => array($model->id),
//            'enableCache'=>true,
    )); ?>
        <?php echo $form->error($model, 'parent_id'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'title'); ?>
        <?php echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'title'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'image'); ?>
        <?php echo $form->textField($model, 'image', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'image'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'is_active', array('label' => 'Visible')); ?>
        <?php echo $form->checkBox($model, 'is_active'); ?>
        <?php echo $form->error($model, 'is_active'); ?>
    </div>
    <?php $this->endClip();?>

    <?php $this->beginClip('description');?>
    <?php
    $langTab = array();
    $langList = Language::model()->findAll('status=1');
    if (count($langList)) {
        foreach ($langList as $i => $lang) {
            $this->beginClip($lang->name);
            if ($model->isNewRecord) {
                $languageCategory = new LanguageCategory();
                $languageCategory->locale = $lang->locale;
            }
            else {
                $languageCategory = LanguageCategory::model()->findByAttributes(array(
                    'category_id' => $model->id,
                    'locale' => $lang->locale,
                ));
                if (!$languageCategory) {
                    $languageCategory = new LanguageCategory();
                    $languageCategory->locale = $lang->locale;
                }
            }
            $this->renderPartial('Site.views.admin.languageCategory._form', array(
                'model' => $languageCategory,
                'form' => $form,
                'i' => $i,
            ));
            $this->endClip();
            $langTab[$lang->name] = $this->Clips[$lang->name];
        }

        if (count($langTab)) {
            $this->widget('zii.widgets.jui.CJuiTabs', array(
                'id' => 'language-tabs',
                'tabs' => $langTab,
            ));
        }
    }
    ?>
    <?php $this->endClip();?>

    <?php
    $tabs = array(
        'Description' => $this->Clips['description'],
        'Info' => $this->Clips['info'],
    );
    $this->widget('zii.widgets.jui.CJuiTabs', array(
        'id' => 'category-tabs',
        'tabs' => $tabs,
    ));
    ?>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->